<?php
    $name = $_POST['name'];
    $upass = $_POST['upass'];
    $spass = $_POST['spass'];
//    var_dump($_POST);
//    die;
    if(!empty($name) && !empty($upass) && !empty($spass)){
        if($upass==$spass){
            $link = mysqli_connect("localhost","root","") or die("数据连接失败");
            mysqli_set_charset($link,"utf8");
            mysqli_select_db($link,"bbs");
            $sql = "insert into user (userName,password,lastlogin) values('{$name}','{$upass}',1021)";
            $result = mysqli_query($link, $sql);;
            if($result && mysqli_affected_rows($link)>0) {
                echo "<script>alert('注册成功！');window.location.href='../login.php';</script>";
                die;
            }else{
                echo "<script>alert('注册失败！');window.location.href='../register.php';</script>";
                die;
            }

        }else{
            echo "<script>alert('密码和确认密码不一致！');window.location.href='../register.php';</script>";
            die;
        }
    }else{
        echo "<script>alert('所有条件都不能为空！');window.location.href='../register.php';</script>";
        die;
    }
    mysqli_close($link);